<?php
	session_start();
	
	if (!isset($_SESSION['sesi_login']))
		header("Location:../../index.php");

	@chdir("../../");
	define('ABS_URL',str_replace("\\","/",getcwd()));
	require ABS_URL.'/engine/Smarty.class.php';
	require ABS_URL."/functions/class.query.inc.php";
	$smarty = new Smarty();
	require ABS_URL."/dev_con.inc.php";
	require ABS_URL."/functions/func_file.php";
	$queryData = new queryData();
	$queryData->baseConfig();
	require ABS_URL."/functions/func_content.php";
	require ABS_URL."/langs/".BASE_LANGUAGE.'.inc.php';
	require $queryData->get_curr_dir(dirname(__FILE__))."/langs/".BASE_LANGUAGE.'.inc.php';

	$kategori = trim($_POST['kategori']);
	$tipe = trim($_POST['tipe']);
	$keterangan = trim($_POST['keterangan']);
	
	if (strtolower(ACT_VER)=="hapus") {
		$kode = (int) $_GET['kode'];
		$sql = "DELETE FROM tbl_kategori WHERE idx='".$kode."'";
		$qry = mysql_query($sql);
		($qry) ? $_SESSION['sesi_ver'] = $queryData->cekAksi($kode,'delete') : $_SESSION['sesi_ver'] = '';
		$act = 'lihat';
	} else {		
		$a = array($kategori,$tipe,$keterangan);
		$b = array('empty','empty','empty');
		$c = array($CAT_TITLE,$CAT_TYPE,$CAT_DESC);
		switch (strtolower($_POST['act_ver'])) {
			case "input" :
				$result = $queryData->NotificationCheck($a,$b,$c);
				if (empty($result)) {						
					$sql = "INSERT INTO tbl_kategori VALUES(NULL,'".$kategori."','".$tipe."','".$keterangan."')";
					$qry = mysql_query($sql);
			  } else {
				  $_SESSION['sesi_ver'] = $DEV_ACTION_NOTIFICATION;
				  foreach($result as $data) {
					  $_SESSION['sesi_ver'] .= '<br />- '.$data;
				  }
				  $act = 'tambah';
			  }
			break;
			case "edit" :
				$kode = (int) $_POST['kode'];;
				$result = $queryData->NotificationCheck($a,$b,$c);
				if (empty($result)) {						
					$sql = "UPDATE tbl_kategori SET kategori='".$kategori."', tipe='".$tipe."', keterangan='".$keterangan."' WHERE idx='".$kode."'";
					//print $sql;
					$qry = mysql_query($sql);
				} else {
					$_SESSION['sesi_ver'] = $DEV_ACTION_NOTIFICATION;
					foreach($result as $data) {
						$_SESSION['sesi_ver'] .= '<br />- '.$data;
					}
					$act = 'tambah';
				}
			break;
		}
	}

	if (isset($_SESSION['sesi_login'])) {
		header('Location:../../?show='.SHOW.'&showview='.SHOWVIEW.'&act='.$act.'&limitdown=0');
	} else {
		header("Location:../../index.php");
	};
?>
